package com.dc.project.system.controller;

import com.dc.common.core.MasterSlaveDto;
import com.dc.common.validated.InsertGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.system.service.SysUserRoleService;
import com.dc.project.system.entity.SysUserRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 用户角色表(SysUserRole)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-03 16:42:33
 */
@RestController
@RequestMapping("sysUserRole")
@Api(tags = "用户角色表")
public class SysUserRoleController {
    /**
     * 服务对象
     */
    @Autowired
    private SysUserRoleService sysUserRoleService;


    /**
     * 新增用户角色表
     *
     * @param sysUserRole
     * @return
     */
    @PostMapping
    @ApiOperation("新增用户角色表")
    @RequiresPermissions("system:sysUserRole:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody SysUserRole sysUserRole) {
        return this.sysUserRoleService.add(sysUserRole);
    }

    /**
     * 批量新增用户角色表
     *
     * @param dto
     * @return
     */
    @PostMapping("roles")
    @ApiOperation("批量新增用户角色表")
    @RequiresPermissions("system:sysUserRole:add")
    public ResultVo addRoles(@Validated(value = {InsertGroup.class}) @RequestBody MasterSlaveDto<Integer, SysUserRole> dto) {
        return this.sysUserRoleService.addRoles(dto);
    }

    /**
     * 根据主键删除用户角色表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除用户角色表")
    @RequiresPermissions("system:sysUserRole:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.sysUserRoleService.delete(id);
    }

}